package com.lys.service.impl;

import com.lys.dao.UserDao;
import com.lys.entity.User;
import com.lys.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	private Logger logger = Logger.getLogger(UserServiceImpl.class);

	@Override
	public boolean add(User user){
		Integer count=0;
		try {
			count=userDao.add(user);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return  count>0;

	}

	@Override
	public boolean update(User user) {
		Integer count=0;
		try {
			count=userDao.update(user);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return  count>0;

	}

	@Override
	public boolean deleteUserById(Integer userId) {
		Integer count=0;
		try {
			count=userDao.deleteUserById(userId+"");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return  count>0;

	}

	@Override
	public User getUser(Integer userId, String loginName) {
		User user=null;
		try {
			user=userDao.getUser(userId,loginName);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;

	}

	@Override
	public List<User> getUserList(Integer currentPageNo, Integer pageSize) {
		List<User> userList=null;
		try {
			userList=userDao.getUserList(currentPageNo,pageSize);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return userList;

	}

	@Override
	public int count() {
		Integer count=null;
		try {
			count=userDao.count();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;

	}

}
